<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">


<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 control-label">公司名称：</label>-->
                            <!--<div class="col-sm-9">-->
                                <!--<input id="companyName" name="companyName" class="form-control" type="text" maxlength="30" style="width: 400px;">-->
                            <!--</div>-->
                        <!--</div>-->


                        <div class="form-group">
                            <input id="companyDetail" name="companyDetail" type="hidden" class="form-control">
                            <label class="col-sm-2 control-label">公司介绍：</label>
                            <div class="col-sm-9">
                                <div class="ibox-content no-padding">
                                    <div id="content_sn" class="summernote"></div>
                                </div>
                            </div>
                        </div>
                        <div class="text-right form-group">
                            <div class="col-sm-11">
                                <button type="submit" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    $().ready(function () {
        getInfo();
        validateRule();
    });

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });

    function getInfo() {
        $('.summernote').summernote({
            height: '320px',
            lang: 'zh-CN',
            callbacks: {
                onImageUpload: function (files, editor, $editable) {
                    sendFile(files);
                }
            }
        });

        $.ajax({
            type: "GET",
            url: "/mp/company/getInfo",
            dataType: "JSON",
            async: false,
            success: function (data) {
                console.log("data",data);
                if(data != null){
                    $('#companyName').val(data.companyName);
                    $('#companyTel').val(data.companyTel);
                    $('#companyDetail').val(data.companyDetail);

                    $('#content_sn').summernote('code', data.companyDetail);
                }
            }
        });

    }

    function save() {
        var content_sn = $("#content_sn").summernote('code');
        $("#companyDetail").val(content_sn);
        $.ajax({
            cache: true,
            type: "POST",
            url: "/mp/company/save",
            data: $('#signupForm').serialize(), // 你的formid
            async: false,
            success: function (data) {
                layer.msg("操作成功");
            }
        });
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                companyName: {
                    required: true
                },
                companyTel:{
                    required: true
                },
                companyDetail:{
                    required: true
                }
            },
            messages: {
                companyName: {
                    required: icon + "必填"
                },
                companyTel: {
                    required: icon + "必填"
                },
                companyDetail: {
                    required: icon + "必填"
                }
            }
        })
    }

</script>
</body>
</html>